在開發過程當中,曾經一度想要取得 IndexStore
取得的管道
/path/to/MyTest.xcodeproj
由三個元素組合而成
ENV
DerivedData: ~/Library/Developer/Xcode/DerivedDataProject Name
: MyTestHASH
: ABCD(假設)
hash("/path/to/MyTest.xcodeproj")
因此最終的路徑為
"~/Library/Developer/Xcode/DerivedData/MyTest-(hash("/path/to/MyTest.xcodeproj"))"
也就是
"~/Library/Developer/Xcode/DerivedData/MyTest-ABCD"
import Foundation
import CryptoSwift
public struct DerivedPath {
public static let `default`: String = "\(NSHomeDirectory())/Library/Developer/Xcode/DerivedData"
private let name: String
public init?(_ path: String) {
let url = URL(fileURLWithPath: path)
let fileName: String = url.deletingPathExtension().lastPathComponent
let absolutePath = url.path
let data = Data(absolutePath.utf8)
let digestBytes: [UInt8] = [UInt8](data.md5())
let digest64: [UInt64] = unsafeBitCast(digestBytes, to: [UInt64].self)
var resultStr: [UInt8] = Array<UInt8>(repeating: 0, count: 28)
var startValue: UInt64 = 0
startValue = CFSwapInt64BigToHost(digest64[0])
for index in (0...13).reversed() {
resultStr[index] = UInt8(startValue % 26) + 97 // 'a'
startValue /= 26
}
startValue = CFSwapInt64BigToHost(digest64[1])
for index in (14...27).reversed() {
resultStr[index] = UInt8(startValue % 26) + 97 // 'a'
startValue /= 26
}
guard let derived: String = String(bytes: resultStr, encoding: .utf8) else { return nil }
self.name = "\(fileName)-\(derived)"
}
}